import React from 'react'
import {FormattedMessage} from 'react-intl';
// import validate from '../base/Validate.js'
import Input from '../base/Input.js'
import {newUser,uploadFile} from '../../actions/userManageAction'
const NewUser = React.createClass({
	getInitialState(){
		return {
			form_data:{
				username:'',
				password:'',
			}
		}
	},
	handleSubmit(event){
		event.preventDefault()
		console.log($('.form-error').length)
		if ($('.form-error').length !==0) {
			return
		}
		newUser(this.state.form_data)
	},
	handleChange(targetData){
		let form_data = this.state.form_data
		form_data[targetData.name] = targetData.value;
		this.setState({form_data: form_data})
	},
	fileChange(e){
		let data = {filename: 'file',file: e.target.files[0]}
		uploadFile(data)
	},
	render(){
		let v1 = {data : {}};
				v1.data[validate.notempty] = <FormattedMessage id='not empty' description='为空验证'defaultMessage='Hello, Howard'/>;
				v1.minLengthByte        = {min:6,message:'至少6个字节'}
				v1.maxLengthByte        = {max:10,message:'不超过10个字节'}
				// v1.minLengthChar           = {min:5,message:'至少5个字节'}
				// v1.maxLengthChar           = {max:10,message:'不超过10个字节'}
		return(
			<div>
				<input type='file' id='upload_file' name='file' onChange={this.fileChange}/>
				<form className="form-horizontal" ref='formbox1'>
				  <div className="form-group">
				    <label  className="col-sm-2 control-label">账号名称</label>
				    <div className="col-sm-120">
				    <input className='none'/>
				      <Input 
				      		placeholder="请输入账号名称" 
				      		validate={v1} 
				      		type='text' 
				      		onChange={this.handleChange} 
				      		data-target="username"
				      		name="sdf"
				      	/>
				    </div>
				  </div>
				  <div className="form-group">
				    <label  className="col-sm-2 control-label">密码</label>
				    <div className="col-sm-10">
				      <Input 
				      		placeholder="请输入密码" 
				      		type='password' 
				      		onChange={this.handleChange} 
				      		data-target="password"
				      		name='23'
				      	/>
				    </div>
				  </div>
				  <div className="form-group">
				    <div className="col-sm-offset-2 col-sm-10">
				      <button className="btn btn-default" onClick={this.handleSubmit}>保存</button>
				    </div>
				  </div>
				</form>
			</div>
		)
	}
})

export default NewUser